package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 维护错误码之后也要维护错误描述
 * 1.错误码定义规则为5个数字
 */
public enum DonationExceptionEnum implements IntegerEnum<Integer> {
    OFFICIAL_DONATION_RECORDS_DO_NOT_EXIST(300001, "官方捐赠记录不存在"),
    CURRENT_OFFICIAL_DONATION_RECORDS_HAVE_BEEN_REVIEWED(300002, "当前官方捐赠记录已审核"),
    THE_RECOMMENDED_HELP_RECORD_DOES_NOT_EXIST(300003, "推荐帮扶记录不存在"),
    IT_IS_RECOMMENDED_TO_HELP_EXPORT_EXCEPTIONS(300004, "推荐帮扶导出出现异常，请联系管理员"),
    CANNOT_BE_DELETED_IF_APPROVED(300005, "审核通过不能删除"),
    THE_CURRENT_PUBLIC_WELFARE_DONATION_HAS_BEEN_REVIEWED(300006, "当前公益捐款已审核"),


    ;


    private Integer code;
    private String msg;

    DonationExceptionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @JsonCreator
    public static DonationExceptionEnum getByCode(int code) {
        for (DonationExceptionEnum value : DonationExceptionEnum.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
